#include "widget.h"
#include "ui_widget.h"


#define PLOT_RbcColor QColor(Qt::red)
#define PLOT_PltColor QColor(Qt::green)



Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

}

Widget::~Widget()
{
    delete ui;
}

bool Widget::eventFilter(QObject *target, QEvent *e)
{

}

void Widget::on_pushButton_clicked()
{
   // m_plot1 = new PointPlot(161, 145, this);
    m_plot1 = new PointPlot(91, 145, this);
    PointPlot::PointLabel label;
    label.topLabel = "WBC";
    label.xLabel = "WAS";
    label.yLabel = "LAS";
    m_plot1->setLabel(label);
    m_plot1->setBkgroundColor(Qt::black);
    m_plot1->InitScatterPlot();

    QVector<double> x(250), y(250);
    for (int j=0; j<250; ++j)
    {
        x[j] = j/250.0 * 50;
        y[j] = qrand()%50;
    }
    m_plot1->setScatterData(x,y, Qt::green);

    QVector<double> x1(250), y1(250);
    for (int j=0; j<250; ++j)
    {
        x1[j] = j;
        y1[j] = qrand()%250;
    }
    m_plot1->setScatterData(x1,y1, Qt::white);

    QVector<double> x2(250), y2(250);
    for (int j=0; j<250; ++j)
    {
        x2[j] = j/250.0*50+75;
        y2[j] = qrand()%50+75;
    }
    m_plot1->setScatterData(x2,y2, Qt::red);


    QVector<double> x3(250), y3(250);
    for (int j=0; j<250; ++j)
    {
        x3[j] = j/250.0*50+90;
        y3[j] = qrand()%50+220;
    }
     m_plot1->setScatterData(x3,y3, QColor(0, 180, 180));


    QVector<double> x4(250), y4(250);
    for (int j=0; j<250; ++j)
    {
        x4[j] = j/250.0 *50+100;
        y4[j] = qrand()% 50+220;
    }

    m_plot1->setScatterData(x4,y4, QColor(200,0,200));
    m_plot1->show();


}


void Widget::on_pushButton_2_clicked()
{
   // PointPlot *m_plot = new PointPlot(161, 145, this);
    PointPlot *m_plot = new PointPlot(145, 91, this);
    PointPlot::PointLabel label;
    label.topLabel = "WBC";
    label.xLabel = "WAS";
    label.yLabel = "LAS";
    m_plot->InitScatterPlot();
    m_plot->setLabel(label);
    m_plot->setBkgroundColor(Qt::black);
    m_plot->move(200, 0);

    m_plot->show();
}

void Widget::on_pushButton_3_clicked()
{

    PointPlot *m_plot = new PointPlot(161, 145, this);
    PointPlot::PointLabel label;
    label.topLabel = "RBC";
    label.xLabel = "fL";
    label.yLabel = "";
    m_plot->setLabel(label);
    m_plot->InitHistogram(PointPlot::HgT_RBC);
    m_plot->setBkgroundColor(Qt::black);
    m_plot->move(400, 0);



    QVector<double> x0(60), y0(60);
    for (int i=40; i<100; ++i)
    {
      x0[i-40] = i;
      y0[i-40] = 30+50*qExp(-i/250.0)*qCos(i/10.0);
    }


    QPen pen;
    pen.setColor(Qt::white);
    pen.setWidth(2);
    m_plot->getPlot()->addGraph(0);
    m_plot->getPlot()->graph(0)->setPen(pen);
    m_plot->getPlot()->graph(0)->setData(x0, y0);
    m_plot->getPlot()->graph(0)->setBrush(QBrush(PLOT_RbcColor));
    m_plot->getPlot()->graph(0)->rescaleAxes(true);


    QVector<double> x1(100), y1(100);
    for (int i=0; i<100; ++i)
    {
      x1[i] = 20;
      y1[i] = i*2 ;
    }
    m_plot->getPlot()->addGraph();
    m_plot->getPlot()->graph(1)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDot,3));
    pen.setStyle(Qt::DashLine);
    pen.setWidth(1);
    pen.setColor(Qt::white);
    m_plot->getPlot()->graph(1)->setPen(pen);
    m_plot->getPlot()->graph(1)->setData(x1, y1);

    m_plot->replot();
    m_plot->show();

}

void Widget::on_pushButton_4_clicked()
{

    m_plot4 = new PointPlot(161, 145, this);
    PointPlot::PointLabel label;
    label.topLabel = "PLT";
    label.xLabel = "fL";
    label.yLabel = "";
    m_plot4->InitHistogram(PointPlot::HgT_PLT);
    m_plot4->setLabel(label);
    m_plot4->setBkgroundColor(Qt::black);
    m_plot4->move(600, 0);

    m_plot4->show();

}

void Widget::on_pushButton_5_clicked()
{
    m_plot1->clearPlot();
}
